package com.heima.pool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author itheima
 * @since 2023-01-07
 */
public class ThreadPool {

    private static volatile ThreadPoolExecutor executor;

    public static ThreadPoolExecutor getInstance() {
        // 检查全局唯一的实例是否为空
        if(executor == null) {
            // 如果为空，我就new一个
            executor = new ThreadPoolExecutor(16,
                    100,
                    2000,
                    TimeUnit.SECONDS,
                    new ArrayBlockingQueue<>(100),
                    null,
                    new ThreadPoolExecutor.AbortPolicy());
        }

        // 如果不为空，我就直接返回
        return executor;
    }

}
